package com.binyouwei.designpatterns.behavior.memento;

/**
 * @author 宾有为
 * @date 2024/7/16 19:32
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：备忘录模式 - 保存一个对象的某个状态，以便在适当的时候恢复对象。
 **/
public class MementoMain {
    public static void main(String[] args) {
        MementoOriginator originator = new MementoOriginator();
        MementoCareTaker careTaker = new MementoCareTaker();
        originator.setState("State #1");
        originator.setState("State #2");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #3");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #4");

        System.out.println("Current State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("First saved State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("Second saved State: " + originator.getState());
    }
}
